'use strict';

const moment = require('moment');

module.exports = app => {
  const { Sequelize } = app;

  const Feedbacks = app.model.define('Feedbacks', {
    id: {
      allowNull: false,
      autoIncrement: true,
      primaryKey: true,
      type: Sequelize.INTEGER
    },
    openId: {
      allowNull: false,
      type: Sequelize.STRING(100)
    },
    nickname: {
      allowNull: false,
      type: Sequelize.STRING(16)
    },
    content: {
      allowNull: false,
      type: Sequelize.STRING(200)
    },
    status: {
      allowNull: false,
      type: Sequelize.INTEGER(1),
      defaultValue: 0
    },
    type: {
      allowNull: false,
      type: Sequelize.INTEGER(1)
    },
    createdAt: {
      allowNull: false,
      type: Sequelize.DATE,
      get() { return moment(this.getDataValue('createdAt')).format('YYYY-MM-DD HH:mm') }
    },
    updatedAt: {
      allowNull: false,
      type: Sequelize.DATE,
      get() { return moment(this.getDataValue('updatedAt')).format('YYYY-MM-DD HH:mm') }
    },
    deletedAt: {
      type: Sequelize.DATE
    }
  }, {
    charset: 'utf8mb4',
    collate: 'utf8mb4_general_ci',
    comment: '意见反馈表',
  });

  return Feedbacks;

};